home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 13139 / 13139.xpi / content / overlay.js next >
Text File  |  2009-10-17  |  54KB  |  1,135 lines

  1. /*
  2. *├ºok k─▒sa textler g├╢zard─▒ edilsin = yap─▒ld─▒
  3. * frameset sayfalarda bug var, position frame in ba┼ƒlad─▒─ƒ─▒ yere g├╢re al─▒n─▒yor (├ºok da dert de─ƒil), as─▒l sorun scroll ile ilgili
  4. * icona sa─ƒ click g├╢zard─▒ edilsin = yap─▒ld─▒
  5. * geni┼ƒletilebilinsin = yap─▒ld─▒
  6. * site se├ºmece -> art─▒k SQLite de duruyor, sadece interface ve de─ƒi┼ƒtirme fonksiyonu laz─▒m = yap─▒ld─▒
  7. * sitedeki linkler de bunun i├ºinde a├º─▒labilir = ask─▒da
  8. * iconun ├╝st├╝ne gelindi─ƒinde site listesi ├º─▒kabilir = yap─▒ld─▒
  9. * halen bazen kapanm─▒yor d─▒┼ƒar─▒ t─▒klay─▒nca = buton konuldu
  10. * baz─▒ sitelerde kelime encode edilsin(escape()) baz─▒lar─▒nda adilmesin diye database e bu se├ºenek eklensin
  11. * baz─▒siteleri full modda a├ºmak daha iyi olabilir, belki database eklenebilir
  12. * metamenu yer varm─▒ diye baks─▒n, yoksa di─ƒer taraftan ├º─▒ks─▒n
  13. * copy to clipboard se├ºene─ƒi ├º─▒k─▒yor lakin kullan─▒┼ƒs─▒z olabilir, incelensin kullan─▒┼ƒs─▒z ise kald─▒r─▒ls─▒n = ┼ƒimdilik kapal─▒
  14. * uzun se├ºimlerdeiki gecikmeli a├º─▒l─▒┼ƒ uyuz bir ┼ƒey olabilir, incelensin uyuzsa kapat─▒ls─▒n
  15. * google translate metamenu ye entegre edilsin, hatta terc├╝meleri sayfaya uygulayabilsin oldu─ƒu gibi = yap─▒ld─▒
  16. * s├╝r├╝kleyerek ta┼ƒ─▒ma = yap─▒ld─▒
  17. * ubiquity diye bir ┼ƒey var, ondan esinlenilebilir
  18. * translate edilen text gizlenmesin direk silinsin= yap─▒ld─▒
  19. * metamen├╝de sadece ilk 3 g├╢sterilsin = yap─▒ld─▒;
  20. * yeni y├╝klemede ayar sayfas─▒ a├º─▒ls─▒n, ama bu y├╢nlendirme ├╝zerinden olsun = yap─▒ld─▒
  21. * ayar sayfas─▒ linki konulsun = yap─▒ld─▒
  22. * aramaya uygun siteler se├ºilsin ve listeye eklensin = en temelleri eklendi
  23. * referrer temizlemek laz─▒m = ask─▒da
  24. */
  25. /*extension by mrtksn*/
  26.  
  27. try {
  28.  
  29.     var whatTheHell = {};
  30.     (function () {
  31.         this.versionNum = '0.81';
  32.         this.SelectedTxt = "";
  33.         this.FarePosSol = 0;
  34.         this.FarePosUst = 0;
  35.         this.urlList = new Array();
  36.  
  37.         this.init = function () {
  38.             try {
  39.                 /*capture mouse up so can init the icon*/
  40.                 window.document.addEventListener("mouseup", function (evt) {
  41.                     whatTheHell.initIcon(evt)
  42.                 },
  43.                 false);
  44.                 /*capture settings page event*/
  45.                 window.document.addEventListener("preparePageData", function (evt) {
  46.                     try {
  47.  
  48.                         var location = evt.target.location.toString().slice(0, 38);
  49.                         if (location != 'http://appwared.com/budaneki/settings/') {
  50.                             alert('can\'t prepare, location wrong:' + location);
  51.                             return false;
  52.                         }
  53.                         /*transfer datato page*/
  54.                         whatTheHell.dataChromeToPage('showPage', whatTheHell.urlList);
  55.  
  56.                     } catch(err) {
  57.                         alert(err);
  58.                     };
  59.                 },
  60.                 false, true);
  61.                 window.document.addEventListener("saveData", function (evt) {
  62.                     try {
  63.                         var location = evt.target.location.toString().slice(0, 38);
  64.                         if (location != 'http://appwared.com/budaneki/settings/') {
  65.                             alert('can\'t save, location wrong:' + location);
  66.                             return false;
  67.                         }
  68.                         /*transfer datato page*/
  69.                         whatTheHell.saveDataFromPage();
  70.  
  71.                     } catch(err) {
  72.                         alert(err);
  73.                     };
  74.                 },
  75.                 false, true);
  76.  
  77.                 /*test the database and create one if there is a problem*/
  78.                 var file = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile);
  79.                 file.append("budaneki.sqlite");
  80.  
  81.                 var storageService = Components.classes["@mozilla.org/storage/service;1"].getService(Components.interfaces.mozIStorageService);
  82.                 var mdbConn = storageService.openDatabase(file); // Will also create the file if it does not exist 
  83.                 var tableExists = mdbConn.tableExists("budanekiLinkDb");
  84.                 if (tableExists == false) {
  85.                     var start = new Array();
  86.                     whatTheHell.resetDb(false);
  87.                 } else {
  88.  
  89.                     try {
  90.                         var statement = mdbConn.createStatement("SELECT * FROM budanekiLinkDb");
  91.                         statement.executeStep();
  92.                         var rid = statement.row.id;
  93.                     } catch(err) {
  94.                         var start = new Array();
  95.                         whatTheHell.resetDb(false);
  96.                     }
  97.                 }
  98.                 /*load the linkList*/
  99.                 whatTheHell.generateLinkList();
  100.  
  101.                 /*open new tab on first run*/
  102.                 var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
  103.                 try {
  104.                     var lastVer = prefs.getCharPref("budaneki.lastVersion");
  105.                 } catch(err) {
  106.                     var lastVer = 0;
  107.                 }
  108.                 if (whatTheHell.versionNum != lastVer) {
  109.                    setTimeout(function(){
  110.                    gBrowser.selectedTab = gBrowser.addTab("http://redirect.appwared.com/budaneki");
  111.                    }, 1500);
  112.                    
  113.  
  114.                     prefs.setCharPref("budaneki.lastVersion", whatTheHell.versionNum);
  115.                     
  116.                 }
  117.  
  118.             } catch(err) {
  119.                 alert(err);
  120.             }
  121.         }
  122.  
  123.         this.initIcon = function (evt) {
  124.             if (evt.which != 1) {
  125.                 //exit if not left-click
  126.                 return;
  127.             }
  128.             // get the selected text
  129.             whatTheHell.SelectedTxt = whatTheHell.getSelection();
  130.  
  131.             //init if text is selected
  132.             try {
  133.                 var winAll = new XPCNativeWrapper(content);
  134.                 var frameDisplay = winAll.document.getElementById("what_the_hell_infoFrame").style.width;
  135.                 frameDisplay = true;
  136.             } catch(err) {
  137.                 var frameDisplay = false;
  138.             }
  139.             var selectionLength = whatTheHell.SelectedTxt.length;
  140.             if (selectionLength >= 3 && selectionLength <= 50 && frameDisplay == false) {
  141.  
  142.                 whatTheHell.showIcon(evt, 0, 5);
  143.  
  144.             } else if (selectionLength >= 50) {
  145.                 whatTheHell.showIcon(evt, 1500, 10);
  146.  
  147.             } else {
  148.  
  149.                 whatTheHell.hideIcon();
  150.             }
  151.  
  152.         }
  153.  
  154.         this.showIcon = function (evt, wait, speed) {
  155.  
  156.             try {
  157.                 whatTheHell.hideIcon();
  158.             } catch(err) {}
  159.             //working with the content
  160.             var win = new XPCNativeWrapper(document.commandDispatcher.focusedWindow);
  161.             var winContent = new XPCNativeWrapper(content);
  162.             //hide the icon if its out of the frame
  163.             //win.document.addEventListener("mouseout", function(evt){whatTheHell.hideIcon()}, false);
  164.             //position of the cursor   
  165.             FarePosSol = whatTheHell.mouseLeft(evt);
  166.             FarePosUst = whatTheHell.mouseTop(evt);
  167.  
  168.             // create the DIV element holding the icon
  169.             var what_the_hell_icon = win.document.createElement("div");
  170.             what_the_hell_icon.id = "what_the_hell_icon";
  171.             what_the_hell_icon.style.position = "absolute";
  172.             what_the_hell_icon.style.left = FarePosSol - 12 + "px";
  173.             what_the_hell_icon.style.top = FarePosUst - 34 + "px";
  174.             what_the_hell_icon.style.display = "block";
  175.             what_the_hell_icon.style.opacity = 0;
  176.             what_the_hell_icon.style.zIndex = "9999";
  177.             what_the_hell_icon.innerHTML = "<img id=\"what_the_hell_icon_img\" src=\"" + whatTheHell.qsiconPng + "\" />";
  178.             what_the_hell_icon.style.cursor = "pointer";
  179.             win.document.body.appendChild(what_the_hell_icon);
  180.             win.document.getElementById("what_the_hell_icon_img").style.cssFloat = "left";
  181.             try {
  182.                 var linkList = whatTheHell.urlList;
  183.                 /*escape string if needed*/
  184.                 if (linkList[0]['escape_url'] == 1) {
  185.                     var selection = escape(whatTheHell.SelectedTxt);
  186.                 } else {
  187.                     var selection = whatTheHell.SelectedTxt;
  188.                 }
  189.                 var initUrl = linkList[0]['url'] + selection;
  190.                 win.document.getElementById("what_the_hell_icon_img").addEventListener("mousedown", function (evt) {
  191.                     whatTheHell.initFrame(evt, initUrl)
  192.                 },
  193.                 false);
  194.  
  195.                 win.document.getElementById("what_the_hell_icon").addEventListener("mouseover", function (evt) {
  196.                     whatTheHell.showMetaMenu(evt)
  197.                 },
  198.                 false);
  199.                 win.addEventListener("mousemove", whatTheHell.trackCursorMetaMenu, false);
  200.                 /*metamenu copy disabled*/
  201.                 //win.document.getElementById("what_the_hell_icon").addEventListener("mouseout", function(evt){whatTheHell.showMetaMenuCopy(evt)}, false);
  202.             } catch(err) {
  203.                 alert(err);
  204.             }
  205.  
  206.             //fade to opac
  207.             iconShowTimeOut = window.setTimeout(whatTheHell.opacityChangeAnimate, wait, what_the_hell_icon, speed, 0);
  208.  
  209.         }
  210.         this.hideIcon = function () {
  211.  
  212.             //working with the content
  213.             var win = new XPCNativeWrapper(document.commandDispatcher.focusedWindow);
  214.  
  215.             //remove icon
  216.             try {
  217.                 var what_the_hell_icon = win.document.getElementById("what_the_hell_icon");
  218.                 win.document.body.removeChild(what_the_hell_icon);
  219.                 win.removeEventListener("mousemove", whatTheHell.trackCursorMetaMenu, false);
  220.             }
  221.             catch(err) {
  222.                 //Handle errors here
  223.             }
  224.             return true;
  225.         }
  226.  
  227.         this.showMetaMenu = function (evt) {
  228.             var win = new XPCNativeWrapper(document.commandDispatcher.focusedWindow);
  229.             evt.stopPropagation();
  230.             win.document.addEventListener("mouseover", function (evt) {
  231.                 whatTheHell.hideMetaMenu(evt)
  232.             },
  233.             false);
  234.  
  235.             try {
  236.  
  237.                 win.document.getElementById("what_the_hell_meta_menu").innerHtml;
  238.  
  239.             } catch(err) {
  240.  
  241.                 var what_the_hell_meta_menu = win.document.createElement("div");
  242.                 what_the_hell_meta_menu.id = 'what_the_hell_meta_menu';
  243.                 what_the_hell_meta_menu.style.position = 'relative';
  244.                 what_the_hell_meta_menu.style.cssFloat = 'left';
  245.                 what_the_hell_meta_menu.style.opacity = 0;
  246.                 what_the_hell_meta_menu.style.marginLeft = '10px';
  247.                 what_the_hell_meta_menu.style.background = "url(" + whatTheHell.metamenubgPng + ")";
  248.                 what_the_hell_meta_menu.style.backgroundRepeat = 'repeat-x';
  249.                 win.document.getElementById("what_the_hell_icon").appendChild(what_the_hell_meta_menu);
  250.                 //fade to opac
  251.                 whatTheHell.opacityChangeAnimate(what_the_hell_meta_menu, 25, 0);
  252.  
  253.                 // add google translate icon
  254.                 var what_the_hell_meta_menu_gtranslate = win.document.createElement("img");
  255.                 what_the_hell_meta_menu_gtranslate.src = whatTheHell.metamenugPng;
  256.                 what_the_hell_meta_menu_gtranslate.style.position = 'relative';
  257.                 what_the_hell_meta_menu_gtranslate.style.cssFloat = 'left';
  258.                 what_the_hell_meta_menu_gtranslate.style.marginLeft = '-15px';
  259.                 what_the_hell_meta_menu_gtranslate.addEventListener('mousedown', function (evt) {
  260.                     whatTheHell.googleTranlateGetLang(whatTheHell.SelectedTxt);
  261.                 },
  262.                 false);
  263.                 what_the_hell_meta_menu_gtranslate.addEventListener("mouseout", function () {
  264.  
  265.                     whatTheHell.makeAllVisible(what_the_hell_meta_menu);
  266.                 },
  267.                 false);
  268.                 win.document.getElementById("what_the_hell_meta_menu").appendChild(what_the_hell_meta_menu_gtranslate);
  269.  
  270.                 var linkList = whatTheHell.urlList;
  271.                 for (var i = 0; i < linkList.length; i++) {
  272.                     if (i == 3) {
  273.                         var what_the_hell_infoFrame_link_last_img = win.document.createElement("img");
  274.                         what_the_hell_infoFrame_link_last_img.src = whatTheHell.metamenubgrPng;
  275.                         what_the_hell_infoFrame_link_last_img.style.display = 'none';
  276.                         what_the_hell_infoFrame_link_last_img.style.position = 'relative';
  277.                         what_the_hell_infoFrame_link_last_img.style.cssFloat = 'left';
  278.                         what_the_hell_infoFrame_link_last_img.style.marginRight = '-4px';
  279.                         win.document.getElementById("what_the_hell_meta_menu").appendChild(what_the_hell_infoFrame_link_last_img);
  280.                         break;
  281.                     }
  282.                     var what_the_hell_infoFrame_link = win.document.createElement("a");
  283.                     //if its the first loop
  284.                     if (i == 0) {
  285.                         what_the_hell_infoFrame_link.style.marginLeft = '-5px';
  286.                         // what_the_hell_infoFrame_link.style.display = 'block';
  287.                     } else {
  288.                         // what_the_hell_infoFrame_link.style.display = 'none';
  289.                     }
  290.                     /*escape string if needed*/
  291.                     if (linkList[i]['escape_url'] == 1) {
  292.                         var selection = escape(whatTheHell.SelectedTxt);
  293.                     } else {
  294.                         var selection = whatTheHell.SelectedTxt;
  295.                     }
  296.                     what_the_hell_infoFrame_link.href = linkList[i]['url'] + selection;
  297.                     what_the_hell_infoFrame_link.target = "what_the_hell_infoFrame";
  298.                     what_the_hell_infoFrame_link.id = "what_the_hell_infoFrame_link_" + i;
  299.                     what_the_hell_infoFrame_link.innerHTML = linkList[i]['name'];
  300.                     what_the_hell_infoFrame_link.style.position = 'relative';
  301.                     what_the_hell_infoFrame_link.style.cssFloat = 'left';
  302.                     what_the_hell_infoFrame_link.style.color = '#000';
  303.                     what_the_hell_infoFrame_link.style.display = 'none';
  304.                     /*make all invisible*/
  305.                     what_the_hell_infoFrame_link.style.background = "url(" + whatTheHell.metamenubglPng + ")";
  306.                     what_the_hell_infoFrame_link.style.backgroundRepeat = "no-repeat";
  307.                     what_the_hell_infoFrame_link.style.paddingLeft = "4px";
  308.                     what_the_hell_infoFrame_link.style.fontSize = '9px';
  309.                     what_the_hell_infoFrame_link.style.textDecoration = 'none';
  310.                     what_the_hell_infoFrame_link.style.textShadow = '1px 1px 2px #6374AB';
  311.                     what_the_hell_infoFrame_link.style.fontFamily = "verdana";
  312.                     what_the_hell_infoFrame_link.style.fontWeight = "normal";
  313.                     what_the_hell_infoFrame_link.style.lineHeight = "2.3";
  314.                     what_the_hell_infoFrame_link.addEventListener("mousedown", function (evt) {
  315.                         whatTheHell.initFrame(evt, this.href)
  316.                     },
  317.                     false);
  318.                     win.document.getElementById("what_the_hell_meta_menu").appendChild(what_the_hell_infoFrame_link);
  319.  
  320.                     //if its the last loop
  321.                     if (i == (linkList.length - 1)) {
  322.                         var what_the_hell_infoFrame_link_last_img = win.document.createElement("img");
  323.                         what_the_hell_infoFrame_link_last_img.src = whatTheHell.metamenubgrPng;
  324.                         what_the_hell_infoFrame_link_last_img.style.display = 'none';
  325.                         what_the_hell_infoFrame_link_last_img.style.position = 'relative';
  326.                         what_the_hell_infoFrame_link_last_img.style.cssFloat = 'left';
  327.                         what_the_hell_infoFrame_link_last_img.style.marginRight = '-4px';
  328.                         win.document.getElementById("what_the_hell_meta_menu").appendChild(what_the_hell_infoFrame_link_last_img);
  329.  
  330.                     }
  331.  
  332.                 }
  333.             }
  334.         }
  335.  
  336.         this.hideMetaMenu = function (evt) {
  337.             var win = new XPCNativeWrapper(document.commandDispatcher.focusedWindow);
  338.             evt.stopPropagation();
  339.             win.document.removeEventListener("mouseover", whatTheHell.hideMetaMenu, false);
  340.  
  341.             //if the element exists
  342.             try {
  343.                 var what_the_hell_meta_menu = win.document.getElementById("what_the_hell_meta_menu");
  344.                 win.document.getElementById("what_the_hell_icon").removeChild(what_the_hell_meta_menu);
  345.  
  346.             } catch(err) {
  347.                 // alert(err);
  348.             }
  349.         }
  350.  
  351.         //track position of the cursor, so hide if the max distance has reached
  352.         this.trackCursorMetaMenu = function (evt) {
  353.             var maxTop = 35;
  354.             var maxBottom = 95;
  355.             var win = new XPCNativeWrapper(document.commandDispatcher.focusedWindow);
  356.             if ((evt.pageY > (win.document.getElementById('what_the_hell_icon').offsetTop + maxBottom)) || (evt.pageY < (win.document.getElementById('what_the_hell_icon').offsetTop - maxTop))) {
  357.                 whatTheHell.hideIcon();
  358.             }
  359.  
  360.         }
  361.  
  362.         this.showMetaMenuCopy = function (evt) {
  363.             var win = new XPCNativeWrapper(document.commandDispatcher.focusedWindow);
  364.  
  365.             try {
  366.                 win.document.getElementById("what_the_hell_metamenu_copy_img").src;
  367.             } catch(err) {
  368.                 var eposl = whatTheHell.mouseLeft(evt);
  369.                 var epost = whatTheHell.mouseTop(evt);
  370.                 var iposl = parseFloat(win.document.getElementById("what_the_hell_icon").style.left);
  371.                 var ipost = parseFloat(win.document.getElementById("what_the_hell_icon").style.top);
  372.                 if (epost <= ipost && eposl >= iposl && eposl < (iposl + 22)) {
  373.                     var what_the_hell_metamenu_copy_img = win.document.createElement("img");
  374.                     what_the_hell_metamenu_copy_img.id = 'what_the_hell_metamenu_copy_img';
  375.                     what_the_hell_metamenu_copy_img.src = whatTheHell.metamenucPng;
  376.                     what_the_hell_metamenu_copy_img.style.position = 'absolute';
  377.                     what_the_hell_metamenu_copy_img.style.cssFloat = 'left';
  378.                     what_the_hell_metamenu_copy_img.style.zIndex = '9999';
  379.                     what_the_hell_metamenu_copy_img.style.cursor = "pointer";
  380.                     what_the_hell_metamenu_copy_img.style.left = iposl + 2 + 'px';
  381.                     what_the_hell_metamenu_copy_img.style.top = ipost - 16 + 'px';
  382.                     what_the_hell_metamenu_copy_img.addEventListener('mouseout', function () {
  383.                         whatTheHell.hideMetaMenuCopy()
  384.                     },
  385.                     false);
  386.                     what_the_hell_metamenu_copy_img.addEventListener('click', function (evt) {
  387.                         whatTheHell.metaMenuCopyToCb(evt)
  388.                     },
  389.                     false);
  390.                     win.document.body.appendChild(what_the_hell_metamenu_copy_img);
  391.  
  392.                 }
  393.  
  394.             }
  395.         }
  396.  
  397.         this.hideMetaMenuCopy = function () {
  398.             var win = new XPCNativeWrapper(document.commandDispatcher.focusedWindow);
  399.             try {
  400.                 var obj = win.document.getElementById("what_the_hell_metamenu_copy_img");
  401.                 win.document.body.removeChild(obj);
  402.             } catch(err) {
  403.                 alert(err);
  404.             }
  405.         }
  406.         this.metaMenuCopyToCb = function (evt) {
  407.             evt.stopPropagation();
  408.             var win = new XPCNativeWrapper(document.commandDispatcher.focusedWindow);
  409.             try {
  410.                 const gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper);
  411.                 gClipboardHelper.copyString(whatTheHell.getSelection());
  412.                 //hide icons
  413.                 whatTheHell.hideMetaMenuCopy();
  414.                 whatTheHell.hideIcon();
  415.             } catch(err) {
  416.                 //alert(err);
  417.             }
  418.  
  419.         }
  420.  
  421.         this.makeAllVisible = function (obj) {
  422.  
  423.             var children = obj.childNodes;
  424.             for (var i = 0; i < children.length; i++) {
  425.                 children[i].style.display = 'block';
  426.  
  427.             };
  428.  
  429.         }
  430.  
  431.         //function for generating the link list [from the database for an example]
  432.         this.generateLinkList = function () {
  433.  
  434.             /*SQLite ile bombastik*/
  435.             try {
  436.                 whatTheHell.urlList = new Array();
  437.                 var file = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile);
  438.                 file.append("budaneki.sqlite");
  439.  
  440.                 var storageService = Components.classes["@mozilla.org/storage/service;1"].getService(Components.interfaces.mozIStorageService);
  441.                 var mdbConn = storageService.openDatabase(file); // Will also create the file if it does not exist 
  442.                 var statement = mdbConn.createStatement("SELECT * FROM budanekiLinkDb");
  443.                 try {
  444.                     while (statement.executeStep()) {
  445.                         var urlId = statement.row.id;
  446.                         var urlName = statement.row.name;
  447.                         var urlThe = statement.row.url;
  448.                         var urlEscape = statement.row.escape_url;
  449.                         var urlSize = statement.row.size;
  450.                         var urlType = statement.row.type;
  451.                         whatTheHell.urlList.push({
  452.                             'id': urlId,
  453.                             'name': urlName,
  454.                             'url': urlThe,
  455.                             'escape_url': urlEscape,
  456.                             'size': urlSize,
  457.                             'type': urlType
  458.                         });
  459.                     }
  460.                 }
  461.                 finally {
  462.                     statement.reset();
  463.                 }
  464.  
  465.             } catch(err) {
  466.  
  467.                 alert(err);
  468.             }
  469.             return true;
  470.  
  471.         }
  472.  
  473.         this.resetDb = function (urlList) {
  474.             try {
  475.                 if (urlList == false) {
  476.                     /*list of the default providers*/
  477.                     var urlList = new Array({
  478.                         'name': 'sesli s├╢zl├╝k',
  479.                         'url': 'http://m.seslisozluk.com/?word=',
  480.                         'escape_url': 0,
  481.                         'size': 0,
  482.                         'type': 0
  483.                     },
  484.                     {
  485.                         'name': 'ek┼ƒi s├╢zl├╝k',
  486.                         'url': 'http://sozluk.sourtimes.org/show.asp?t=',
  487.                         'escape_url': 0,
  488.                         'size': 0,
  489.                         'type': 0
  490.                     },
  491.                     {
  492.                         'name': 'Google',
  493.                         'url': 'http://www.google.com/search?q=',
  494.                         'escape_url': 0,
  495.                         'size': 0,
  496.                         'type': 0
  497.                     },
  498.                     {
  499.                         'name': 'Google images',
  500.                         'url': 'http://images.google.com/images?q=',
  501.                         'escape_url': 0,
  502.                         'size': 0,
  503.                         'type': 0
  504.                     });
  505.                 }
  506.  
  507.                 
  508.                 var file = Components.classes["@mozilla.org/file/directory_service;1"]
  509.                      .getService(Components.interfaces.nsIProperties)
  510.                      .get("ProfD", Components.interfaces.nsIFile);
  511.                       file.append("budaneki.sqlite");
  512.  
  513.                          var storageService = Components.classes["@mozilla.org/storage/service;1"]
  514.                         .getService(Components.interfaces.mozIStorageService);
  515.                         var mdbConn = storageService.openDatabase(file);
  516.  
  517.                 var statement = mdbConn.createStatement('DROP TABLE IF EXISTS "budanekiLinkDb"');
  518.                 statement.execute();
  519.                 /*drop and create providers table */
  520.                 var statement = mdbConn.createStatement('CREATE TABLE "budanekiLinkDb" ("id" INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL , "name" CHAR, "url" CHAR, "escape_url" INTEGER NOT NULL  DEFAULT 0, "size" INTEGER NOT NULL  DEFAULT 0, "type" INTEGER NOT NULL  DEFAULT 0);');
  521.                 statement.execute();
  522.                 /*insert*/
  523.                 for (var i = 0; i < urlList.length; i++) {
  524.  
  525.                     var statement = mdbConn.createStatement("INSERT INTO \"budanekiLinkDb\" VALUES(NULL,'" + urlList[i].name + "','" + urlList[i].url + "'," + urlList[i].escape_url + "," + urlList[i].size + "," + urlList[i].type + ");");
  526.                     statement.execute();
  527.                 }
  528.  
  529.             } catch(err) {
  530.  
  531.                alert(err);
  532.             }
  533.         }
  534.  
  535.         this.opacityChangeAnimate = function (obj, wait, i) {
  536.             obj.style.opacity = "0." + i;
  537.             i++;
  538.             if (i < 9) {
  539.                 setTimeout(whatTheHell.opacityChangeAnimate, wait, obj, wait, i);
  540.             } else {
  541.                 obj.style.opacity = 1;
  542.             }
  543.         }
  544.         this.initIframe = function (evt, url) {
  545.             evt.preventDefault();
  546.  
  547.             try {
  548.                 var win = new XPCNativeWrapper(content);
  549.                 win.document.getElementById("what_the_hell_infoFrame_iframe").src = url;
  550.             } catch(err) {
  551.                 alert(err);
  552.             }
  553.         }
  554.         this.initFrame = function (evt, initUrlNow) {
  555.  
  556.             if (evt.which != 1) {
  557.                 //exit if not left-click
  558.                 return;
  559.             }
  560.  
  561.             var win = new XPCNativeWrapper(content);
  562.             var winFocWin = new XPCNativeWrapper(document.commandDispatcher.focusedWindow);
  563.  
  564.             /*Find and define the screen size*/
  565.             var winWidth = win.innerWidth;
  566.             var winHeight = win.innerHeight;
  567.             var docWidth = win.document.body.clientWidth;
  568.             var docHeight = win.document.body.clientHeight;
  569.  
  570.             //ready to use dimensions
  571.             if (docWidth == 0 || docWidth < winWidth) {
  572.                 var docWidthPx = "100%";
  573.             } else {
  574.                 var docWidthPx = docWidth + "px";
  575.             }
  576.             if (docHeight == 0 || docHeight < winHeight) {
  577.                 var docHeightPx = "100%";
  578.             } else {
  579.                 var docHeightPx = docHeight + "px";
  580.             }
  581.  
  582.             //correct FarePosXY for winFocWin, if the page is framed
  583.             if (win.document.documentElement.scrollTop !== winFocWin.document.documentElement.scrollTop) {
  584.                 FarePosUst = FarePosUst - winFocWin.document.documentElement.scrollTop;
  585.             }
  586.             if (win.document.documentElement.scrollLeft !== winFocWin.document.documentElement.scrollLeft) {
  587.                 FarePosSol = FarePosSol - winFocWin.document.documentElement.scrollLeft;
  588.             }
  589.             // reposition if there is no enough space 
  590.             if ((FarePosSol + 630) > (winWidth + win.document.documentElement.scrollLeft) && (FarePosSol - 630 > 0)) {
  591.                 var FarePosSolFixed = (winWidth + win.document.documentElement.scrollLeft) - 630;
  592.             } else {
  593.                 var FarePosSolFixed = FarePosSol;
  594.             }
  595.  
  596.             if ((FarePosUst + 320) > winHeight + win.document.documentElement.scrollTop) {
  597.  
  598.                 var FarePosUstFixed = FarePosUst - 320;
  599.             } else {
  600.                 var FarePosUstFixed = FarePosUst;
  601.             }
  602.  
  603.             try {
  604.                 if (win.document.body.tagName != "BODY") {
  605.                     var x = window._content;
  606.                     var pageHtml = x.document.getElementsByTagName("html")[0];
  607.                     var theBody = x.document.createElement("body");
  608.                     pageHtml.appendChild(theBody);
  609.  
  610.                 }
  611.             } catch(err) {
  612.                 //alert(err);
  613.             }
  614.  
  615.             // create the DIV element holding the frame.
  616.             var what_the_hell_infoFrame = win.document.createElement("div");
  617.  
  618.             //content of the frame        
  619.             what_the_hell_infoFrame.style.display = "block";
  620.             what_the_hell_infoFrame.style.position = "absolute";
  621.             what_the_hell_infoFrame.style.left = FarePosSolFixed + 'px';
  622.             what_the_hell_infoFrame.style.top = FarePosUstFixed + 'px';
  623.             what_the_hell_infoFrame.style.padding = "5px";
  624.             what_the_hell_infoFrame.style.paddingTop = "3px";
  625.             what_the_hell_infoFrame.style.width = '600px';
  626.             //what_the_hell_infoFrame.style.height = '300px';
  627.  
  628.             what_the_hell_infoFrame.style.background = "url(" + whatTheHell.bgtpxPng + ")";
  629.             what_the_hell_infoFrame.id = "what_the_hell_infoFrame";
  630.             what_the_hell_infoFrame.style.zIndex = "99999";
  631.             win.document.body.appendChild(what_the_hell_infoFrame);
  632.             //create the menu links container
  633.             var what_the_hell_infoFrame_link_container = win.document.createElement("div");
  634.             what_the_hell_infoFrame_link_container.id = 'what_the_hell_infoFrame_link_container';
  635.             what_the_hell_infoFrame_link_container.style.padding = 0;
  636.             what_the_hell_infoFrame_link_container.style.margin = 0;
  637.             what_the_hell_infoFrame_link_container.style.position = 'relative';
  638.             what_the_hell_infoFrame_link_container.style.cssFloat = 'left';
  639.             what_the_hell_infoFrame_link_container.style.width = '91%';
  640.             win.document.getElementById("what_the_hell_infoFrame").appendChild(what_the_hell_infoFrame_link_container);
  641.  
  642.             //create menu links
  643.             try {
  644.                 var linkList = whatTheHell.urlList;
  645.                 for (var i = 0; i < linkList.length; i++) {
  646.                     var what_the_hell_infoFrame_link = win.document.createElement("a");
  647.                     /*escape string if needed*/
  648.                     if (linkList[i]['escape_url'] == 1) {
  649.                         var selection = escape(whatTheHell.SelectedTxt);
  650.                     } else {
  651.                         var selection = whatTheHell.SelectedTxt;
  652.                     }
  653.                     what_the_hell_infoFrame_link.href = linkList[i]['url'] + selection;
  654.                     what_the_hell_infoFrame_link.target = "what_the_hell_infoFrame";
  655.                     what_the_hell_infoFrame_link.innerHTML = linkList[i]['name'];
  656.                     what_the_hell_infoFrame_link.style.position = 'relative';
  657.                     what_the_hell_infoFrame_link.style.cssFloat = 'left';
  658.                     what_the_hell_infoFrame_link.style.color = '#fff';
  659.                     what_the_hell_infoFrame_link.style.background = '#000';
  660.                     what_the_hell_infoFrame_link.style.padding = '2px';
  661.                     what_the_hell_infoFrame_link.style.marginLeft = '3px';
  662.                     what_the_hell_infoFrame_link.style.marginTop = '2px';
  663.                     what_the_hell_infoFrame_link.style.fontSize = '12px';
  664.                     what_the_hell_infoFrame_link.style.textDecoration = 'none';
  665.                     what_the_hell_infoFrame_link.style.fontFamily = "verdana";
  666.                     what_the_hell_infoFrame_link.style.fontWeight = "normal";
  667.                     what_the_hell_infoFrame_link.style.lineHeight = "1.2";
  668.  
  669.                     win.document.getElementById("what_the_hell_infoFrame_link_container").appendChild(what_the_hell_infoFrame_link);
  670.  
  671.                     /*handle click by javascript*/
  672.                     what_the_hell_infoFrame_link.addEventListener("click", function (evt) {
  673.                         whatTheHell.initIframe(evt, this.href)
  674.                     },
  675.                     false);
  676.  
  677.                 }
  678.             } catch(err) {
  679.                 alert(err);
  680.             }
  681.  
  682.             //create func. buttons container
  683.             var what_the_hell_infoFrame_btn_container = win.document.createElement("div");
  684.             what_the_hell_infoFrame_btn_container.id = 'what_the_hell_infoFrame_btn_container';
  685.             what_the_hell_infoFrame_btn_container.style.padding = 0;
  686.             what_the_hell_infoFrame_btn_container.style.margin = 0;
  687.             what_the_hell_infoFrame_btn_container.style.position = 'relative';
  688.             what_the_hell_infoFrame_btn_container.style.cssFloat = 'right';
  689.             what_the_hell_infoFrame_btn_container.style.width = '50px';
  690.             what_the_hell_infoFrame_btn_container.style.textAlign = 'right';
  691.             win.document.getElementById("what_the_hell_infoFrame").appendChild(what_the_hell_infoFrame_btn_container);
  692.             //create close button
  693.             var what_the_hell_infoFrame_close_btn = win.document.createElement("img");
  694.             what_the_hell_infoFrame_close_btn.id = 'what_the_hell_infoFrame_close_btn';
  695.             what_the_hell_infoFrame_close_btn.src = whatTheHell.cbtnPng;
  696.             what_the_hell_infoFrame_close_btn.style.position = 'relative';
  697.             what_the_hell_infoFrame_close_btn.style.cssFloat = 'right';
  698.             what_the_hell_infoFrame_close_btn.style.opacity = '0.5';
  699.             what_the_hell_infoFrame_close_btn.style.marginTop = '2px';
  700.             what_the_hell_infoFrame_close_btn.addEventListener("mouseover", function () {
  701.                 whatTheHell.makeOpac(this)
  702.             },
  703.             false);
  704.             what_the_hell_infoFrame_close_btn.addEventListener("mouseout", function () {
  705.                 whatTheHell.makeTransparent(this, '0.5')
  706.             },
  707.             false);
  708.             what_the_hell_infoFrame_close_btn.addEventListener("click", function (evt) {
  709.                 whatTheHell.hideFrame(evt)
  710.             },
  711.             false);
  712.             win.document.getElementById("what_the_hell_infoFrame_btn_container").appendChild(what_the_hell_infoFrame_close_btn);
  713.             //create full button
  714.             var what_the_hell_infoFrame_full_btn = win.document.createElement("img");
  715.             what_the_hell_infoFrame_full_btn.id = 'what_the_hell_infoFrame_full_btn';
  716.             what_the_hell_infoFrame_full_btn.src = whatTheHell.fbtnPng;
  717.             what_the_hell_infoFrame_full_btn.style.position = 'relative';
  718.             what_the_hell_infoFrame_full_btn.style.cssFloat = 'right';
  719.             what_the_hell_infoFrame_full_btn.style.opacity = '0.5';
  720.             what_the_hell_infoFrame_full_btn.style.margin = '2px';
  721.             what_the_hell_infoFrame_full_btn.addEventListener("mouseover", function () {
  722.                 whatTheHell.makeOpac(this)
  723.             },
  724.             false);
  725.             what_the_hell_infoFrame_full_btn.addEventListener("mouseout", function () {
  726.                 whatTheHell.makeTransparent(this, '0.5')
  727.             },
  728.             false);
  729.             what_the_hell_infoFrame_full_btn.addEventListener("click", function () {
  730.                 whatTheHell.frameMakeFullScr()
  731.             },
  732.             false);
  733.             win.document.getElementById("what_the_hell_infoFrame_btn_container").appendChild(what_the_hell_infoFrame_full_btn);
  734.             //create the settings link
  735.             var what_the_hell_infoFrame_s_btn = win.document.createElement("img");
  736.             what_the_hell_infoFrame_s_btn.id = 'what_the_hell_infoFrame_s_btn';
  737.             what_the_hell_infoFrame_s_btn.src = whatTheHell.sbtnPng;
  738.             what_the_hell_infoFrame_s_btn.style.position = 'relative';
  739.             what_the_hell_infoFrame_s_btn.style.cssFloat = 'right';
  740.             what_the_hell_infoFrame_s_btn.style.opacity = '0.5';
  741.             what_the_hell_infoFrame_s_btn.style.margin = '2px';
  742.             what_the_hell_infoFrame_s_btn.addEventListener("mouseover", function () {
  743.                 whatTheHell.makeOpac(this)
  744.             },
  745.             false);
  746.             what_the_hell_infoFrame_s_btn.addEventListener("mouseout", function () {
  747.                 whatTheHell.makeTransparent(this, '0.5')
  748.             },
  749.             false);
  750.             what_the_hell_infoFrame_s_btn.addEventListener("click", function () {
  751.                 gBrowser.selectedTab = gBrowser.addTab("http://redirect.appwared.com/budaneki");
  752.  
  753.             },
  754.             false);
  755.             win.document.getElementById("what_the_hell_infoFrame_btn_container").appendChild(what_the_hell_infoFrame_s_btn);
  756.  
  757.             //create the iframe
  758.             var what_the_hell_infoFrame_iframe = win.document.createElement("iframe");
  759.             what_the_hell_infoFrame_iframe.name = 'what_the_hell_infoFrame';
  760.             what_the_hell_infoFrame_iframe.id = 'what_the_hell_infoFrame_iframe';
  761.             what_the_hell_infoFrame_iframe.style.border = 'none';
  762.             what_the_hell_infoFrame_iframe.style.width = '100%';
  763.             what_the_hell_infoFrame_iframe.style.height = '280px';
  764.             var frameHeight = parseFloat(what_the_hell_infoFrame.style.height);
  765.  
  766.             what_the_hell_infoFrame_iframe.style.height = (frameHeight - 20) + 'px';
  767.             what_the_hell_infoFrame_iframe.style.position = 'relative';
  768.             what_the_hell_infoFrame_iframe.style.cssFloat = 'left';
  769.             what_the_hell_infoFrame_iframe.style.clear = 'left';
  770.             what_the_hell_infoFrame_iframe.style.position = "relative";
  771.             what_the_hell_infoFrame_iframe.style.Float = "left";
  772.             what_the_hell_infoFrame_iframe.style.clear = "both";            
  773.             
  774.             win.document.getElementById("what_the_hell_infoFrame").appendChild(what_the_hell_infoFrame_iframe);
  775.             //init url 
  776.             whatTheHell.initIframe(evt, initUrlNow);
  777.  
  778.  
  779.  
  780.             //create back layer to handle the click.        
  781.             var what_the_hell_backlayer = win.document.createElement("div");
  782.             what_the_hell_backlayer.style.display = "block";
  783.             what_the_hell_backlayer.style.position = "absolute";
  784.             what_the_hell_backlayer.style.left = '0px';
  785.             what_the_hell_backlayer.style.top = '0px';
  786.             what_the_hell_backlayer.style.width = docWidthPx;
  787.             what_the_hell_backlayer.style.height = docHeightPx;
  788.             what_the_hell_backlayer.id = "what_the_hell_backlayer";
  789.             what_the_hell_backlayer.style.zIndex = "99998";
  790.             win.document.body.appendChild(what_the_hell_backlayer);
  791.  
  792.             //register events
  793.             win.document.getElementById("what_the_hell_backlayer").addEventListener("click", function () {
  794.                 whatTheHell.hideFrame()
  795.             },
  796.             false);
  797.             win.document.getElementById("what_the_hell_infoFrame").addEventListener("mousedown", function (evt) {
  798.                 whatTheHell.startDrag(evt, what_the_hell_infoFrame)
  799.             },
  800.             false);
  801.  
  802.         }
  803.  
  804.         this.hideFrame = function () {
  805.  
  806.             var win = new XPCNativeWrapper(content);
  807.             //remove frame
  808.             try {
  809.                 var what_the_hell_infoFrame = win.document.getElementById("what_the_hell_infoFrame");
  810.                 win.document.body.removeChild(what_the_hell_infoFrame);
  811.  
  812.                 var what_the_hell_backlayer = win.document.getElementById("what_the_hell_backlayer");
  813.                 win.document.body.removeChild(what_the_hell_backlayer);
  814.                 //stop drag
  815.                 whatTheHell.stopDrag();
  816.  
  817.             }
  818.             catch(err) {
  819.                 //Handle errors here
  820.             }
  821.  
  822.         }
  823.  
  824.         this.makeOpac = function (obj) {
  825.             obj.style.opacity = '1';
  826.         }
  827.         this.makeTransparent = function (obj, value) {
  828.             obj.style.opacity = value;
  829.         }
  830.         this.frameMakeFullScr = function () {
  831.             var win = new XPCNativeWrapper(content);
  832.             try {
  833.                 var what_the_hell_infoFrame = win.document.getElementById("what_the_hell_infoFrame");
  834.                 what_the_hell_infoFrame.style.left = win.document.documentElement.scrollLeft + 10 + 'px';
  835.                 what_the_hell_infoFrame.style.top = win.document.documentElement.scrollTop + 65 + 'px';
  836.                 what_the_hell_infoFrame.style.width = '95%';
  837.                 what_the_hell_infoFrame.style.height = '90%';
  838.                 var frameHeight = parseFloat(what_the_hell_infoFrame.offsetHeight);
  839.                 win.document.getElementById("what_the_hell_infoFrame_iframe").style.height = (frameHeight - 30) + 'px';
  840.                 win.document.getElementById("what_the_hell_infoFrame_full_btn").style.display = 'none';
  841.                 var what_the_hell_backlayer = win.document.getElementById("what_the_hell_backlayer");
  842.                 win.document.body.removeChild(what_the_hell_backlayer);
  843.  
  844.             } catch(err) {
  845.                 alert(err);
  846.             }
  847.         }
  848.  
  849.         this.startDrag = function (evt, obj) {
  850.             //check the original target to prevent img" or "a" drag
  851.             var orgTargetTagName = evt.originalTarget.tagName;
  852.  
  853.             if (orgTargetTagName == 'IMG' || orgTargetTagName == 'A') {
  854.                 return false;
  855.             }
  856.  
  857.             try {
  858.                 var objX = evt.pageX - obj.offsetLeft;
  859.                 var objY = evt.pageY - obj.offsetTop;
  860.  
  861.                 var win = new XPCNativeWrapper(content);
  862.                 win.document.getElementById('what_the_hell_infoFrame_iframe').style.display = 'none';
  863.                 win.addEventListener("mousemove", _moveObj = function (event) {
  864.                     whatTheHell.dragObj(event, obj, objX, objY)
  865.                 },
  866.                 false);
  867.  
  868.                 obj.addEventListener("mouseup", function () {
  869.                     whatTheHell.stopDrag(_moveObj)
  870.                 },
  871.                 false);
  872.  
  873.             } catch(err) {
  874.                 alert('startDrag' + err);
  875.             }
  876.         }
  877.         this.stopDrag = function (moveObj) {
  878.             var win = new XPCNativeWrapper(content);
  879.             win.document.getElementById('what_the_hell_infoFrame_iframe').style.display = 'block';
  880.             try {
  881.  
  882.                 win.removeEventListener("mousemove", moveObj, false);
  883.             } catch(err) {
  884.                 alert('stopdrag' + err);
  885.             }
  886.  
  887.         }
  888.  
  889.         this.dragObj = function (evt, obj, objX, objY) {
  890.             try {
  891.                 obj.style.left = evt.pageX - objX + 'px';
  892.                 obj.style.top = evt.pageY - objY + 'px';
  893.             } catch(err) {
  894.                 alert('dragObj' + err);
  895.             }
  896.         }
  897.  
  898.         this.mouseLeft = function mouseX(evt) {
  899.             if (evt.pageX) return evt.pageX;
  900.             else if (evt.clientX) return evt.clientX + (window.document.documentElement.scrollLeft ? window.document.documentElement.scrollLeft : window.document.body.scrollLeft);
  901.             else return null;
  902.         }
  903.         this.mouseTop = function mouseY(evt) {
  904.             if (evt.pageY) return evt.pageY;
  905.             else if (evt.clientY) return evt.clientY + (window.document.documentElement.scrollTop ? window.document.documentElement.scrollTop : window.document.body.scrollTop);
  906.             else return null;
  907.         }
  908.  
  909.         this.getSelection = function () {
  910.             var win = new XPCNativeWrapper(document.commandDispatcher.focusedWindow);
  911.  
  912.             var selection = "";
  913.  
  914.             var focusedWindow = new XPCNativeWrapper(document.commandDispatcher.focusedWindow, 'document', 'getSelection()');
  915.             selection = focusedWindow.getSelection().toString();
  916.  
  917.             // Strip newlines
  918.             //  selection = selection.replace(/(\n|\r|\t)+/g, " ");
  919.             // Strip spaces at start and end.
  920.             selection = selection.replace(/(^\s+)|(\s+$)/g, "");
  921.  
  922.             // Remove certain characters at the beginning and end of every word
  923.             for (i = 0; i < selection.length; i++) {
  924.                 selection[i] = selection[i].replace(/^(\&|\(|\)|\[|\]|\{|\}|"|,|\.|!|\?|'|:|;)+/, "");
  925.                 selection[i] = selection[i].replace(/(\&|\(|\)|\[|\]|\{|\}|"|,|\.|!|\?|'|:|;)+$/, "");
  926.             }
  927.             return selection;
  928.         }
  929.         /*parse google response into json, then into javascriptobject, req. FF3.0*/
  930.         this.googleResponseToObject = function (str) {
  931.             try {
  932.                 var start = str.indexOf('{');
  933.                 var end = str.lastIndexOf('}');
  934.                 return whatTheHell.jsonDecode(str.slice(start, (end + 1)));
  935.             } catch(err) {
  936.                 alert(err);
  937.                 return false;
  938.             }
  939.         }
  940.  
  941.         this.googleTranlateGetLang = function(txt){
  942.         try {
  943.                 /*get the language*/
  944.                 var langDetectUrl = 'http://www.google.com/uds/GlangDetect?callback=google.language.callbacks.id100&context=22&q=' + txt.slice(0, 50) + '&key=notsupplied&v=1.0';
  945.  
  946.  
  947.          
  948.             var req = new XMLHttpRequest();
  949.             req.open('GET', langDetectUrl, true);
  950.             req.onreadystatechange = function (aEvt) {
  951.             if (req.readyState == 4) {
  952.             if(req.status == 200){
  953.             var langDetectObj = whatTheHell.googleResponseToObject(req.responseText);
  954.                 /*decide the final language*/
  955.                 if (langDetectObj.language == 'en') {
  956.                     var toLang = 'tr';
  957.                 } else if (langDetectObj.language != 'en') {
  958.                     var toLang = 'en';
  959.                 }
  960.             whatTheHell.googleTranslateDo(txt,langDetectObj.language,toLang);                
  961.             }else{
  962.            return false;
  963.            }
  964.             }
  965.             };
  966.             req.send(null);
  967.             
  968.             } catch(err) {
  969.                 //alert(err);
  970.             }
  971.  
  972.                 
  973.                 
  974.     
  975.         }
  976.         this.googleTranslateDo = function (txt,from,to){
  977.         try {
  978.                 var transUrl = '';
  979.                 var transObject = '';
  980.                 var resultedString = '';
  981.                 var i = 0;
  982.                 /*process the selection by dividing it to pieces of 350 chr each (google translate api allows up to 400 chr)*/
  983.  
  984.                 transUrl = 'http://www.google.com/uds/Gtranslate?callback=google.language.callbacks.id101&context=22&q=' + txt.slice(0, 390) + '&langpair=' + from + '|' + to + '&key=notsupplied&v=1.0';
  985.             
  986.             var req = new XMLHttpRequest();
  987.             req.open('GET', transUrl , true);
  988.             req.onreadystatechange = function (aEvt) {
  989.             if (req.readyState == 4) {
  990.             if(req.status == 200){
  991.             transObject = whatTheHell.googleResponseToObject(req.responseText);
  992.             whatTheHell.replaceSelection(transObject.translatedText);
  993.             }else{
  994.            return false;
  995.            }
  996.             }
  997.             };
  998.             req.send(null);
  999.             
  1000.             } catch(err) {
  1001.                 //alert(err);
  1002.             }
  1003.         
  1004.         }
  1005.  
  1006.         this.replaceSelection = function (txt) {
  1007.             try {
  1008.                 var win = new XPCNativeWrapper(document.commandDispatcher.focusedWindow);
  1009.                 var idNum = whatTheHell.getNumByDate();
  1010.                 ranges = [];
  1011.                 sel = win.getSelection();
  1012.                 range = sel.getRangeAt(0);
  1013.                 /*move node to an invisible node*/
  1014.                 var oldNode = win.document.createElement("span");
  1015.                 oldNode.style.display = 'none';
  1016.                 oldNode.id = 'oldNode_' + idNum;
  1017.                 range.deleteContents();
  1018.  
  1019.                 /*insert the new node*/
  1020.                 var newNode = win.document.createElement("span");
  1021.                 newNode.innerHTML = txt;
  1022.                 newNode.style.opacity = '0.1';
  1023.                 newNode.id = 'newNode_' + idNum;
  1024.                 range.insertNode(newNode);
  1025.                 whatTheHell.opacityChangeAnimate(newNode, 25, 1);
  1026.                 return idNum;
  1027.             } catch(err) {
  1028.                 alert(err);
  1029.             }
  1030.         }
  1031.         this.getNumByDate = function () {
  1032.             Today = new Date();
  1033.             var ms = Today.getHours().toString() + Today.getMinutes().toString() + Today.getMilliseconds().toString();
  1034.             return ms;
  1035.         }
  1036.  
  1037.         this.jsonDecode = function (thing) {
  1038.             var Ci = Components.interfaces;
  1039.             var Cc = Components.classes;
  1040.             var nativeJSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
  1041.             return nativeJSON.decode(thing);
  1042.         }
  1043.         this.jsonEncode = function (thing) {
  1044.             var Ci = Components.interfaces;
  1045.             var Cc = Components.classes;
  1046.             var nativeJSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
  1047.             return nativeJSON.encode(thing);
  1048.         }
  1049.         /*transfer array or object to the page*/
  1050.         this.dataChromeToPage = function (evtName, data) {
  1051.             try {
  1052.                 var win = new XPCNativeWrapper(document.commandDispatcher.focusedWindow);
  1053.                 win.document.getElementById('chromedata').innerHTML = whatTheHell.jsonEncode(data);
  1054.                 var evt = document.createEvent("Events");
  1055.                 evt.initEvent(evtName, true, false);
  1056.                 win.document.getElementById('chromedata').dispatchEvent(evt);
  1057.                 return true;
  1058.             } catch(err) {
  1059.                 return false;
  1060.             }
  1061.         }
  1062.         this.saveDataFromPage = function (evt) {
  1063.             var win = new XPCNativeWrapper(document.commandDispatcher.focusedWindow);
  1064.             try {
  1065.                 var linklist = win.document.getElementById('linklist');
  1066.                 if (linklist.hasChildNodes())
  1067.                 // So, first we check if the object is not empty, if the object has child nodes
  1068.                 {
  1069.                     var children = linklist.childNodes;
  1070.                     var urlList = new Array();
  1071.                     for (var i = 1; i < children.length; i++) {
  1072.                         item = {
  1073.                             'name': children[i].getAttribute("name"),
  1074.                             'url': children[i].getAttribute("url"),
  1075.                             'escape_url': children[i].getAttribute("escape_url"),
  1076.                             'size': children[i].getAttribute("size"),
  1077.                             'type': children[i].getAttribute("type")
  1078.                         };
  1079.                         urlList.push(item);
  1080.                     };
  1081.                     whatTheHell.resetDb(urlList);
  1082.                     whatTheHell.generateLinkList();
  1083.  
  1084.                 };
  1085.             } catch(err) {
  1086.                 alert('save:' + err);
  1087.             }
  1088.         }
  1089.         this.convertImgToDataUrl = function (url) {
  1090.             if (!url) return null;
  1091.             try {
  1092.                 var ioserv = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
  1093.                 var channel = ioserv.newChannel(url, 0, null);
  1094.                 var stream = channel.open();
  1095.  
  1096.                 if (channel instanceof Ci.nsIHttpChannel && channel.responseStatus != 200) {
  1097.                     return null;
  1098.                 }
  1099.  
  1100.                 var bstream = Cc["@mozilla.org/binaryinputstream;1"].createInstance(Ci.nsIBinaryInputStream);
  1101.                 bstream.setInputStream(stream);
  1102.  
  1103.                 var size = 0;
  1104.                 var file_data = "";
  1105.                 while (size = bstream.available()) {
  1106.                     file_data += bstream.readBytes(size);
  1107.                 }
  1108.                 var data = btoa(file_data);
  1109.                 return "data:image;base64," + data;
  1110.             } catch(e) {}
  1111.             return null;
  1112.         }
  1113.         /*prepare images*/
  1114.         this.bgtpxPng = whatTheHell.convertImgToDataUrl('chrome://budaneki/skin/bgtpx.png');
  1115.         this.cbtnPng = whatTheHell.convertImgToDataUrl('chrome://budaneki/skin/cbtn.png');
  1116.         this.fbtnPng = whatTheHell.convertImgToDataUrl('chrome://budaneki/skin/fbtn.png');
  1117.         this.sbtnPng = whatTheHell.convertImgToDataUrl('chrome://budaneki/skin/sbtn.png');
  1118.         this.metamenubgPng = whatTheHell.convertImgToDataUrl('chrome://budaneki/skin/metamenubg.png');
  1119.         this.metamenubglPng = whatTheHell.convertImgToDataUrl('chrome://budaneki/skin/metamenubgl.png');
  1120.         this.metamenubgrPng = whatTheHell.convertImgToDataUrl('chrome://budaneki/skin/metamenubgr.png');
  1121.         this.metamenugPng = whatTheHell.convertImgToDataUrl('chrome://budaneki/skin/metamenug.png');
  1122.         this.metamenucPng = whatTheHell.convertImgToDataUrl('chrome://budaneki/skin/metamenuc.png');
  1123.         this.qsiconPng = whatTheHell.convertImgToDataUrl('chrome://budaneki/skin/qsicon.png');
  1124.  
  1125.     }).apply(whatTheHell);
  1126.  
  1127.     //register on load;
  1128.     window.addEventListener("load", function (evt) {
  1129.        
  1130.         whatTheHell.init(evt)
  1131.     },
  1132.     false);
  1133. } catch(err) {
  1134.     alert(err);
  1135. }